package com.cdtye.shuoh.service.device.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.Update;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cdtye.shuoh.domain.device.entity.DeviceLocation;
import com.cdtye.shuoh.mapper.device.DeviceLocationMapper;
import com.cdtye.shuoh.service.device.DeviceLocationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class DeviceLocationServiceImpl extends ServiceImpl<DeviceLocationMapper, DeviceLocation> implements DeviceLocationService {
    @Autowired
    private DeviceLocationMapper deviceLocationMapper;

    @Override
    public void insertOrUpdateByDeviceIdentification(DeviceLocation record) {
        if(null!=record.getDeviceIdentification()){
            DeviceLocation deviceLocation = findOneByDeviceIdentification(record.getDeviceIdentification());
            if(null!=deviceLocation){
                UpdateWrapper<DeviceLocation> wrapper = new UpdateWrapper<>();
                wrapper.eq("DEVICE_IDENTIFICATION",record.getDeviceIdentification());
                deviceLocationMapper.update(record,wrapper);
            }else{
                deviceLocationMapper.insert(record);
            }
        }
    }

    @Override
    public DeviceLocation findOneByDeviceIdentification(String deviceIdentification) {
        if(null!=deviceIdentification){
           return deviceLocationMapper.findOneByDeviceIdentification(deviceIdentification);
        }
        return null;
    }

    @Override
    public int deleteByDeviceIdentification(String deviceIdentification) {
        if(null!=deviceIdentification){
            return deviceLocationMapper.deleteByDeviceIdentification(deviceIdentification);
        }
        return 0;
    }

    @Override
    public List<DeviceLocation> getDeviceLocationList() {
        return deviceLocationMapper.getDeviceLocationList();
    }
}
